package com.itlaobing.core;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class JdbcExperienceMySQL {
    public static void main(String[] args) throws SQLException, ClassNotFoundException {

        String driverClassName = "com.mysql.cj.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/itlaobing?serverTimezone=Asia/Shanghai";
        String username = "root";
        String password = "";

        // 1、加载驱动类
        Class<?> c = Class.forName(driverClassName);
        System.out.println(c);
        // 2、建立链接
        Connection connection = DriverManager.getConnection(url,username,password);
        // 3、创建 Statement 实例
        Statement statement = connection.createStatement();
        // 4、发送 SQL 给数据库服务器， 并 获取数据库执行的结果
        int count = statement.executeUpdate("delete from c_emp where id = 6");
        // 5、处理返回结果
        System.out.println(count);
        // 6、释放资源
        statement.close();
        connection.close();
    }
}
